<?php
// 分组管理类
namespace Home\Controller;
use Think\Controller;
class GroupController extends BaseController {
	public function index(){
		$gmod = D("Group");
		
		$appid = $_SESSION["apps"][0]["id"];
		
		$where = array("app_id" => array("eq",$appid),"del" => array("eq",0));
		$result = $gmod->select_group($where);
		
		$this->assign("data",$result);
		$this->display();
	}
	
	
	public function add_group(){
        $data = $_POST;
        $returnData = $this->add_wx_group($data["name"]);
        $data["gid"] = $returnData["group"]["id"];
        $gmod->add($data);
    }
    
	public function edit_group(){		
        $gmod = D("Group");
        $where = array("id"=>array("eq",$_GET["id"]));
        $gData = $gmod->find_group($where,"gid,name");
        $this->edit_wx_group($gData);
        $data["name"] = $_GET["name"];
        $gmod->edit_group($where,$data);
                        
    }
    
	public function del_group(){		
        $gmod = D("Group");
        $where = array("id"=>array("eq",$_GET["id"]));
        $data["del"] = 1;
        $gmod->edit_group($where,$data);
                        
    }

    public function fill_data(){
        $gmod = D("Group");
        $groupsData = $this->group_list();
        
        foreach($groupsData["groups"] as $v){
            $data["gid"] = $v["id"];
            $data["name"] = $v["name"];
            $data["app_id"] = $_SESSION["app"]["member_id"];
            $data["count"] = $v["count"];
            $gmod->add_group($data);
            unset($data);
        }
        
    }
	
}